home *** CD-ROM | disk | FTP | other *** search
-
- PEEKs, POKEs, and SYSes -- Part 28
- -- continued from Part 27 --
-
-
-
-
- Now, let's say we were to run this
-
- example program:
-
-
- 10 DIM AB(1,2),CD%(3),EF$(2)
-
-
- ======================================
- CHART 3: What memory looks like after
- we run the example program:
- --------------------------------------
- label description value addr
- --------------------------------------
-
- TXTTAB--> BASIC program line 2049
- ten.
- End of program. 2078
- VARTAB--> 2079
- ARYTAB--> variable name "a" 65 2079
- variable name "b" 66 2080
- +<-offset pointer(lo) 39 2081
- ! offset pointer(hi) 0 2082
- ! # of dimensions 2 2083
- ! size of dim 2 (hi) 0 2084
- ! size of dim 2 (lo) 3 2085
- ! size of dim 1 (hi) 0 2086
- ! size of dim 1 (lo) 2 2087
- ! ab(0,0) - 5 bytes #0 2088
- ! ab(1,0) - 5 bytes #0 2093
- ! ab(0,1) - 5 bytes #0 2098
- ! ab(1,1) - 5 bytes #0 2103
- ! ab(0,2) - 5 bytes #0 2108
- ! ab(1,2) - 5 bytes #0 2113
- +->variable name "c" 195 2118
- variable name "d" 196 2119
- +<-offset pointer(lo) 15 2120
- ! offset pointer(hi) 0 2121
- ! # of dimensions 1 2122
- ! size of dim 1 (hi) 0 2123
- ! size of dim 1 (lo) 4 2124
- ! cd%(0) - 2 bytes #0 2125
- ! cd%(1) - 2 bytes #0 2127
- ! cd%(2) - 2 bytes #0 2129
- ! cd%(3) - 2 bytes #0 2131
- +->variable name "e" 69 2133
- variable name "f" 198 2134
- +<-offset pointer(lo) 16 2135
- ! offset pointer(hi) 0 2136
- ! # of dimensions 1 2137
- ! size of dim 1 (hi) 0 2138
- ! size of dim 1 (lo) 3 2139
- ! ef$(0) - 3 bytes "" 2140
- ! ef$(1) - 3 bytes "" 2143
- ! ef$(2) - 3 bytes "" 2146
- STREND<+ 2149
- ======================================
-
- And now for the explanation.
-
- (Drum roll please...)
-
- Let's take it from the top.
-
-
- Our BASIC program starts at TXTTAB
-
- (address 2049) and extends to just
-
- before VARTAB (address 2079).
-
- VARTAB and ARYTAB point to the same
-
- place because our sample program used
-
- no simple variables. If we HAD used
-
- simple variables, they would be found
-
- somewhere between VARTAB and ARYTAB.
-
-
- THE FIRST ARRAY: AB
-
-
- The first array our program used was
-
- AB(1,2). So, the address pointed to
-
- by ARYTAB contains the name of our
-
- array. As you recall from our
-
- discussion of simple variables, the
-
- names of real variables have their
-
- high bits turned off. On our chart,
-
- at location 2079, 65 is the ASCII
-
- value of "A". At 2080 we find 66, the
-
- ASCII value of "B".
-
- The next two bytes of memory, 2081
-
- and 2082, contain the offset to the
-
- address of the name of the next
-
- array. 2081 is the low byte and 2082
-
- the high, so to find the address of
-
- the the SECOND array, add 39 (the
-
- contents of 2082) to 2079 (the address
-
- of the FIRST array). If you don't
-
- get 2118, try again. A glance at our
-
- chart shows that the name of the next
-
- array used (CD%) is, indeed, at 2118.
-
- But let's look at the FIRST array
-
- some more. Byte 2083 describes the
-
- number of dimensions. Its value is
-
- two because array AB had two
-
- subscripts.
-
- The next four bytes (2084 to 2087)
-
- tell us the size of each of AB's
-
- dimensions. It takes two bytes per
-
- dimension to describe the size of
-
- the array so the size of this block
-
- will vary. For array AB, 2084-85 tell
-
- us that the rightmost dimension has
-
- three elements (0, 1, and 2). 2086-87
-
- describe the second dimension from
-
- the right. It has two elements (0 and
-
- 1).
-
- Starting at 2088, we find the actual
-
- values of the array variables. Array
-
- AB is a REAL array, so each variable
-
- is represented by five bytes. (You
-
- will remember from our discussion of
-
- simple variables that a real variable
-
- consists of an exponent byte followed
-
- by four mantissa bytes.) Arrays are
-
- stored with the rightmost index
-
- increasing most slowly. Look at
-
- locations 2088 to 2113 to see what I'm
-
- talking about. This array is two
-
- elements by three elements, so there
-
- are six variables reserved. Six
-
- variables times five bytes... hmmm...
-
- The next thirty bytes from 2088 will
-
- contain the values of all the
-
- variables in array AB.
-
- 2088 plus 30 is 2118. That's where
-
- our next array will start. You may
-
- remember that our offset pointer from
-
- the first array pointed to 2118. It
-
- turns out that array offset pointers
-
- always point to the next memory
-
- location after the end of their own
-
- array.
-
-
-
- THE SECOND ARRAY: CD%
-
- The second array our program used
-
- was called CD%, so we can expect to
-
- find the ASCII values for "C" and "D"
-
- in memory locations 2118 and 2119.
-
- You will recall from our discussion of
-
- simple variables that INTEGER names
-
- have the high bit set in both
-
- characters.
-
- 2120 and 2121 are the offset from
-
- second array to the third array.
-
- (2118 + 15 = 2133 ... That's where
-
- EF% should start.)
-
- 2122 holds the number of dimensions
-
- of array CD%. In this case, there was
-
- only one dimension.
-
- 2123 and 2124 describe the size of
-
- that single dimension -- 4 elements.
-
- The size here will always be one
-
- greater than the number used in the
-
- BASIC DIM statement, because element
-
- zero is always counted.
-
- The values of array CD% are stored
-
- starting at 2125. Because this is an
-
- INTEGER array, only two bytes are
-
- needed to hold the values. Unlike
-
- simple integers, subscripted integers
-
- do NOT waste three bytes of memory
-
- per variable. The values of the four
-
- variables in CD% are stored in the
-
- eight memory locations from 2125 to
-
- 2132.
-
-
-
- THE THIRD ARRAY: EF$
-
- The first seven bytes of array EF$
-
- are comparable to the first seven
-
- of CD% -- since both arrays have the
-
- same number of dimensions, both have
-
- the same amount of overhead.
-
- Locations 2133 and 2134 contain the
-
- name -- remember that only the SECOND
-
- byte of a STRING name has the high
-
- bit set.
-
- The offset pointer at 2135 and 2136
-
- points to STREND. That means there
-
- are no more arrays after EF$.
-
- 2137 through 2139 describe the size
-
- of the array -- that stuff should be
-
- old hat to you by now.
-
- 2140 through 2148 contain the
-
- string pointers for the three strings
-
- of array EF$. As you remember from
-
- our discussion of simple variables,
-
- the values of string variables are
-
- not found with the variable name.
-
- Instead, strings are stored between
-
- FRETOP and MEMSIZ. The only
-
- information kept with a string's name
-
- is the length of the string and the
-
- address where its actual contents can
-
- be found.
-
- In string arrays, each element holds
-
- only these three bytes:
-
- Byte 0: The length of the string.
-
- Byte 1: The low byte of the string's
- address.
-
- Byte 2: The high byte of the string's
- address.
-
- ------< continued in Part 29 >--------
-